<template>
    <div class="photoinfo-container">
        <h3>{{photoinfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间: {{photoinfo.time | dateFormat}}</span>
            <span>点击 : {{photoinfo.click}}次</span>
        </p>
        <hr>

        <!-- 缩略图区域 需加载插件 vue-preview -->
        <div class="thumbs">
            <img class="preview-img" v-for="(item, index) in list" :src="item.src"
                 height="100" @click="$preview.open(index, list)" :key="item.src">
        </div>

        <!-- 图片内容区域 -->
        <div class="content" v-html="photoinfo.content"></div>

        <!-- 评论子组件区域 -->
        <comment-box :id="id"></comment-box>
    </div>
</template>
<script>
    import comment from '../subcomponents/comment.vue'  
    import { Toast } from 'mint-ui'
    export default {
        data(){
            return{
                id:this.$route.params.id,//将url地址中传递的id值挂载到data上,方便调用
                photoinfo : {
                    title:"图片详情标题",
                    time:"2019-02-28 11:01:00",
                    click:0,
                    content:"<a ><span>勾践卧薪尝胆地</span></a>"
                },
                list:[]//缩略图数组
            }
        },
        created(){
            // this.getPhotoInfo();
            // this.getThumbs();
        },
        methods:{
            getPhotoInfo(){
                //获取图片数据
                this.$http.get('api/getimageInfo/'+this.id).then(result=>{
                    if(result.body.status == 0){
                        this.photoinfo = result.body.message[0];
                    }else{
                        Toast('获取新闻详情数据失败')
                    }
                })
            },
            getThumbs(){
                //获取缩略图数组
                this.$http.get('api/getthumimages/'+this.id).then(result=>{
                    if(result.body.status == 0){
                        result.body.message.forEach(item =>{//为每个图片加载宽和高
                            item.w = 600;
                            item.h = 400;
                        });
                        //把完整的数据保存到list中
                        this.list = result.body.message;
                    }else{
                        Toast('获取新闻详情数据失败')
                    }
                })
            }
        },
        components:{//用来注册子组件的节点
             'comment-box':comment
        }
    }
</script>
<style lang="scss" scoped>
    .photoinfo-container{
        padding: 0 4px; //上下不给,左右4像素
        h3{
            font-size: 16px;
            text-align: center;
            margin: 15px 0;
            color: #26A2FF;
        }
        .subtitle{
            font-size: 13px;
            // color: #226aff;
            display: flex;//左右对齐
            justify-content: space-between;
        }
        .content{
            font-size: 13px;
            line-height: 13px;
            img{
                width: 100%;
            }
        }
        .thumbs{
            margin: 10px;
            box-shadow: 0 0 8px #999;
        }
    }
</style>
